/**
 *  *2010-5-19 上午10:24:18  add 
 */
package com.base.myproject.client.HR.setting;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BaseObject;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.system.SystemMessage;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.i18n.client.NumberFormat;

/**
 * 薪金项目定义，规定了发放薪水的所有项目
 * 
 * @author Administrator 2010-5-19 javazgw@gmail.com
 */
public class Salary_Item extends BaseJDBCPanel {

	BaseStore<BusiObject> store = null;

	public Salary_Item() {
		super();
		busi = SystemMessage.busi[10];

		init();
	}

	public void init() {
		initWeigetx();
		registerMainStore(store);
		registerStore(store);

	}

	private void setdefault() {
		store.addDefault("bcode", Env.getEnvbcode());

	}

	public void complete() {
		super.complete();
	}

	private void initWeigetx() {
		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);
		v.add(createGrid());
		add(v);
	}

	BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("desc_cn");
		type.getField("desc_cn").setType(String.class);
		type.addField("desc_en");
		type.getField("desc_en").setType(String.class);
		type.addField("ifrate");
		type.getField("ifrate").setType(Boolean.class);
		type.addField("ifAttendance");
		type.getField("ifAttendance").setType(Boolean.class);
		type.addField("iftax");
		type.getField("iftax").setType(Boolean.class);
		type.addField("status");
		type.getField("status").setType(String.class);
		type.addField("ifSalary");
		type.getField("ifSalary").setType(Boolean.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("modifydate");
		type.getField("modifydate").setType(Date.class);
		type.addField("createdate");
		type.getField("createdate").setType(Date.class);
		type.addField("ifSocial");
		type.getField("ifSocial").setType(Boolean.class);
		type.addField("ifBonus");
		type.getField("ifBonus").setType(Boolean.class);
		type.addField("salarytype");
		type.getField("salarytype").setType(String.class);
		type.addField("sort");
		type.getField("sort").setType(Integer.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_Salary_Item");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from hr_Salary_Item order by code");
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}

	BaseGridPanel gridpanel = null;
	BaseGridPanel createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C2 = new ColumnConfig("code", "编码", 80);
		C2.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C2);
		ColumnConfig C12 = new ColumnConfig("salarytype", "项目类型", 80);
		BaseComboBoxForm<BaseObject> box = new BaseComboBoxForm<BaseObject>("code", "name", "dictionary", " where type = 'salary'", true);
		C12.setRenderer(box);
		C12.setEditor(box.getCelEditor());
		columns.add(C12);
		ColumnConfig C3 = new ColumnConfig("desc_cn", "中文描述", 120);
		C3.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("desc_en", "英文描述", 120);
		C4.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C4);
		CheckColumnConfig C6 = new CheckColumnConfig("ifAttendance", "与出勤有关", 70);  
		C6.setEditor(new CellEditor(new CheckBox()));  
		columns.add(C6);
		CheckColumnConfig C7 = new CheckColumnConfig("iftax", "应纳税", 60);  
		C7.setEditor(new CellEditor(new CheckBox()));  
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("status", "状况", 80);
		C8.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C8);
		CheckColumnConfig C9 = new CheckColumnConfig("ifSalary", "是否工资", 60);  
		C9.setEditor(new CellEditor(new CheckBox()));  
		columns.add(C9);
		CheckColumnConfig C10 = new CheckColumnConfig("ifSocial", "是否社保", 60);  
		C10.setEditor(new CellEditor(new CheckBox()));  
		columns.add(C10);
		CheckColumnConfig C11 = new CheckColumnConfig("ifBonus", "是否花红", 60);  
		C11.setEditor(new CellEditor(new CheckBox()));  
		columns.add(C11);
		ColumnConfig C14 = new ColumnConfig("sort", "报表中显示的顺序", 120);  
		NumberField num = new NumberField();
		num.setPropertyEditorType(Integer.class);
		C14.setEditor(new CellEditor(num));  
		columns.add(C14);

		ColumnModel cm = new ColumnModel(columns);
		gridpanel = new BaseGridPanel(getStore(), cm, true, true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		gridpanel.getBg().setSelectionModel(cbs);
		Tools.setResize(gridpanel.getBg(), 1.00, 0.95);
		return gridpanel;
	}
}
